package recursion;

import java.util.Arrays;
import java.util.Scanner;

public class AllSort {
    public static void main(String[] args) {
        int n = new Scanner(System.in).nextInt();
        int [] arr = new int[n];
        for ( n = arr.length-1; n >=0 ; n--) {
            arr[n]=n+1;
        }
        f(arr);
    }

    private static void f(int[] arr) {
        f(arr,0);
    }
    private static void f(int [] arr,int start){

        if(start==arr.length-1){
            System.out.println(Arrays.toString(arr));
            return;
        }
        for (int i = start; i < arr.length; i++) {
            swap(arr, i, start);
            f(arr, start + 1);
            swap(arr, i, start);
        }
    }


    private static void swap(int[] arr, int i, int start) {
        int t = arr[i];
        arr[i]=arr[start];
        arr[start]=t;
    }
}
